#!/usr/bin/expect -f

set timeout 60

# SFTP服务器信息
set sftp_server "10.14.3.136"
set username "testtool01"
set password "sunmi388"
set jarName "[lindex $argv 0]"

# 文件路径
set remote_file "/media/testtool01/8f6e1601-d8df-444f-9604-e1a2b2726aa1/DKPAttachment/AgentFolder/$jarName"

# 本地保存路径
set local_path "./$jarName"

# 使用 expect 下载文件
spawn scp $username@$sftp_server:$remote_file $local_path

# 匹配密码提示并发送密码
expect "password:"
send "$password\r"

# 等待传输完成
expect eof

# 检查下载是否成功
if [ regexp {100%} $expect_out(buffer) ] {
    puts "文件下载成功"
} else {
    puts "文件下载失败"
}